package chapter04;

public class Java23_Object_Enum {
    public static void main(String[] args) {
        // TODO 枚举
        // 特殊的类，包含了一组特定的对象，这些对象（常量）不会发生改变，一般使用大写的标识符
        // 关键字：enum
        // 枚举会将对象设置在最前面，和后面的语法使用分号;隔开
        // 枚举类不能创建对象，其对象在类内部创建
        System.out.println(City.BEIJING.name);
        System.out.println(City.SHANGHAI.code);
        System.out.println(MyCity.BEIJING.name);
        System.out.println(MyCity.SHANGHAI.code);
    }
}
class MyCity {
    public String name;
    public int code;

    public MyCity(String name, int code) {
        this.name = name;
        this.code = code;
    }

    public static final MyCity BEIJING = new MyCity("北京", 1001);
    public static final MyCity SHANGHAI = new MyCity("上海", 1002);
}

// 等价于

enum City {
    BEIJING("北京", 1001),
    SHANGHAI("上海",1002);

    City(String name, int code) {
        this.name = name;
        this.code = code;
    }

    public String name;
    public int code;
}